package com.qfedu.mtl.controller;

import com.alibaba.fastjson.JSON;
import com.qfedu.mtl.entity.Systemlogs;
import com.qfedu.mtl.query.SystemlogsQuery;
import com.qfedu.mtl.service.SystemlogsService;
import com.qfedu.mtl.service.impl.SystemlogsServiceImpl;
import com.qfedu.mtl.util.CharacterUtil;
import com.qfedu.mtl.util.HttpUtil;
import com.qfedu.mtl.util.StrUtil;
import com.qfedu.mtl.util.page.Pager;
import com.qfedu.mtl.util.web.annotation.Controller;
import com.qfedu.mtl.util.web.annotation.RequestMapping;
import com.qfedu.mtl.vo.SystemlogsVo;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

/**
 * @version v1.0
 * @Author NVSonar
 * @Date 2023/9/27 9:06
 * @Email 1595220980@qq.com
 */
@Controller
@RequestMapping("/systemlogs")
public class SystemlogsController {

	SystemlogsService systemlogsService=new SystemlogsServiceImpl();

	@RequestMapping("/add")
	public void add(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
		//设置编码
		CharacterUtil.setContentWithJson(request, response);

		Systemlogs systemlogs=new Systemlogs();

		systemlogs.setMgrId(request.getParameter("mgrId"));
		systemlogs.setLogContent(request.getParameter("logContent"));

		systemlogsService.add(systemlogs);

	}

	@RequestMapping("/list")
	public void list(HttpServletRequest request, HttpServletResponse response) throws IOException {
		//设置编码
		CharacterUtil.setContentWithJson(request, response);

		String page = StrUtil.ifNull(request.getParameter("page"), "1");
		String size = StrUtil.ifNull(request.getParameter("size"), "5");

		SystemlogsQuery systemlogsQuery = HttpUtil.request2Bean(request, SystemlogsQuery.class);

		Pager<Systemlogs> systemlogsPagers = systemlogsService.findPage(Integer.valueOf(page), Integer.valueOf(size), systemlogsQuery);

		SystemlogsVo systemlogsVo=new SystemlogsVo();
		systemlogsVo.setCode(0);
		systemlogsVo.setMsg("");
		systemlogsVo.setCount(systemlogsPagers.getTotal());
		systemlogsVo.setData(systemlogsPagers);

		String s = JSON.toJSONString(systemlogsVo);
		response.getWriter().println(s);


	}

}
